<?php
ob_start();
$mid="";
$rid="";
$url="";
$urltag = FALSE;
    foreach($_GET as $key => $value) {
		if($key == "ourid") {$mid = $value;}
		elseif($key == "rid") {$rid = $value;}
		elseif ($urltag == TRUE && (strlen(strstr($url,"?"))==0)) {$url .="?". $key."=".$value;}
		elseif ($urltag == TRUE && (strlen(strstr($url,"?"))>0)) {$url .="&". $key."=".$value;}
		elseif($key == "url") {
		$urltag = TRUE;
		$url .= $value;}
	}
$db = mysql_connect("mysql513.in.shared-server.net:16033", "JRtu434", "qvoiceDB1");
mysql_select_db("JRtu434", $db);
mysql_query("SET NAMES utf8");
$sql = "select * from manualrental where rid='" . $rid . "' and monid='" . $mid ."'and url='" . $url ."'";
$res = mysql_query($sql);
if(!mysql_num_rows($res)) {
mysql_query("INSERT INTO manualrental (monid,rid,url) VALUES ('".$mid."','".$rid."','".$url."')");	
$res = mysql_query($sql);
$item = mysql_fetch_array($res);
$rand = str_pad(rand(0,99999), 5, "0", STR_PAD_LEFT);
$rand = str_pad($item['uid'], 5, "0",STR_PAD_LEFT).$rand;
mysql_query("UPDATE manualrental set rand='".$rand."' where uid='".$item['uid']."'");
$project = mysql_query("Select name from spireproject where rid='".$rid."'");
$item2 = mysql_fetch_array($project);
$nurl = "http://www.q-voice.net/public/thanks/ssg/tasha_num.php?uid=". $rand."&title=".$item2['name']."&url=".$url;
}
else
{
$res = mysql_query($sql);
$item = mysql_fetch_array($res);

$project = mysql_query("Select name from spireproject where rid='".$rid."'");
$item2 = mysql_fetch_array($project);
$nurl = "http://www.q-voice.net/public/thanks/ssg/tasha_num.php?uid=".$item['rand']."&title=".$item2['name']."&url=".$url;
}
header("Location: " . $nurl);
mysql_close();
ob_flush();
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja">
<!-- ==== document header ==== -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>アンケート画面に移動します</title>
</head>
</html>